package com.bmob.lover.data.bindadapter

import androidx.core.view.GravityCompat
import androidx.databinding.BindingAdapter
import androidx.drawerlayout.widget.DrawerLayout
import com.qmuiteam.qmui.widget.grouplist.QMUICommonListItemView
import com.bmob.lover.app.ext.setDrawerLeftEdgeSize

//  ┏┓　　　┏┓
//┏┛┻━━━┛┻┓
//┃　　　　　　　┃
//┃　　　━　　　┃
//┃　┳┛　┗┳　┃
//┃　　　　　　　┃
//┃　　　┻　　　┃
//┃　　　　　　　┃
//┗━┓　　　┏━┛
//    ┃　　　┃                  神兽保佑
//    ┃　　　┃                  永无BUG！
//    ┃　　　┗━━━┓
//    ┃　　　　　　　┣┓
//    ┃　　　　　　　┏┛
//    ┗┓┓┏━┳┓┏┛
//      ┃┫┫　┃┫┫
//      ┗┻┛　┗┻┛
/**
 * @author The one
 * @date 2021-06-29 09:53
 * @describe TODO
 * @email 625805189@qq.com
 * @remark
 */
object DrawerBindingAdapter {


    @BindingAdapter(value = ["isOpenDrawer"], requireAll = false)
    @JvmStatic
    fun openDrawer(
        drawerLayout: DrawerLayout,
        isOpenDrawer: Boolean
    ) {
        with(drawerLayout) {
            if (isOpenDrawer && !isDrawerOpen(GravityCompat.START)) {
                openDrawer(GravityCompat.START)
            } else if(!isOpenDrawer && isDrawerOpen(GravityCompat.START)) {
                closeDrawer(GravityCompat.START)
            }
        }

    }

    @BindingAdapter(value = ["allowDrawerOpen"], requireAll = false)
    @JvmStatic
    fun allowDrawerOpen(
        drawerLayout: DrawerLayout,
        allowDrawerOpen: Boolean
    ) {
        drawerLayout.setDrawerLockMode(
            if (allowDrawerOpen)
                DrawerLayout.LOCK_MODE_UNLOCKED
            else
                DrawerLayout.LOCK_MODE_LOCKED_CLOSED
        )
    }

    @BindingAdapter(value = ["bindDrawerListener"], requireAll = false)
    @JvmStatic
    fun listenDrawerState(
        drawerLayout: DrawerLayout,
        listener: DrawerLayout.SimpleDrawerListener
    ) {
        drawerLayout.addDrawerListener(listener)
    }

    /**
     * DrawerLayout滑动
     * @param drawerLayout DrawerLayout
     * @param percent Float 滑动的百分比区域
     */
    @BindingAdapter(value = ["dragPercentage"], requireAll = false)
    @JvmStatic
    fun dragPercentage(
        drawerLayout: DrawerLayout,
        percent: Float
    ) {
        setDrawerLeftEdgeSize(drawerLayout.context,drawerLayout,percent)
    }

}